home *** CD-ROM | disk | FTP | other *** search
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- HIGH PRECISION TIMER
- DOCUMENTATION
-
- Version 5.5
- January 14, 1990
-
-
- Public Domain
- by Eagle Performance Software
-
-
-
- TIMERH High Precision Timer Documentation, Version 5.5
-
-
-
- T A B L E O F C O N T E N T S
-
- Features . . . . . . . . . . . . . . . . . . . . . . 3
- Distribution Files . . . . . . . . . . . . . . . . . 3
- Demonstration . . . . . . . . . . . . . . . . . . . . 3
- Simple Programming . . . . . . . . . . . . . . . . . 3
- How It Works . . . . . . . . . . . . . . . . . . . . 4
- Support . . . . . . . . . . . . . . . . . . . . . . . 5
- Reference . . . . . . . . . . . . . . . . . . . . . . 5
- Revisions . . . . . . . . . . . . . . . . . . . . . . 6
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 2
- TIMERH High Precision Timer Documentation, Version 5.5
-
-
- FEATURES
-
- This high precision timer written in Pascal allows you to time events or
- programs with 1 micro-second resolution up to 24 hours. The program
- simply uses the extended resolution of the Intel 8253/8254 timer chip
- which is the same chip that generates an interrupt for the system timer
- (every 1/18.2... seconds).
-
- Compatibility - TIMERH works on all IBM PC, XT, AT, PS/2, and 3270 PC
- compatible computers. The source code can be compiled with either Turbo
- Pascal 5.0, 5.5, or QuickPascal.
-
-
- DISTRIBUTION FILES
-
- In this version, TIMERH55.ARC contains:
-
- TimerH .pas: Timer unit source code.
- TimerH .doc: This file.
- TimeDemo.arc: Demonstration file to show elapsed time.
-
-
- DEMONSTRATION
-
- To get a feeling of the timer, let's run the demonstration program that
- came with the utility. Do the following steps:
-
- 1. Make and run TIMEDEMO.PAS.
- 2. Press RETURN for elapsed time since the beginning of the
- program.
- 3. Press ESC to quit the program.
-
-
- SIMPLE PROGRAMMING
-
- Basically, to time a given event in your program, the source code should
- look like the following:
-
- ...
- begin
- ...
- Timer (Sync); { Optional one time use }
- Timer (Start);
- ...
- { Code to be tested goes here. }
- ...
- Timer (Stop);
- ...
- end.
-
- Start - Timer(Start) resets the initial starting value of T1 so that all
- subsequent splits will be referenced to this point in time. You can use
- this more that once.
-
- Stop - Timer(Stop) takes a split in reference to the last Timer(Start)
-
-
- TIMERH High Precision Timer Page 3
- TIMERH High Precision Timer Documentation, Version 5.5
-
-
- which changes the value of T2. Subsequent uses of Timer(Stop) are
- permitted, but there is a little overhead for its execution that is not
- accounted.
-
- Sync - Timer(Sync), placed just before the first start, resets the timer at
- a zero count. It is recommended that you use the default Sync parameter
- for consistent results. The Sync parameter starts the chip timer zero.
- This puts the next interrupt (which uses about 15-200 microseconds to
- update the system timer) at 1/18.2 seconds away. This makes quick events
- (<1/18.2 seconds) uninterrupted. Since the system timer is independent of
- the real time clock, it doesn't affect the time of day on your computer.
-
- Overhead - The overhead for the elapsed time between the start and stop is
- kept in the value T0. The global value ElapsedTime excludes the overhead
- after Timer(Stop).
-
- Jitter - Most events will be within plus or minus 3 microseconds depending
- on your CPU.
-
-
- HOW IT WORKS
-
- To work both on IBM PC which use the 8253 chip and on the IBM AT using the
- 8254 chip, it is necessary to use the common characteristics of both
- chips:
-
- 1. The output port to the timer for counter 0 which is a utility counter
- is $43 and the input port is $40. The latch code is $00 to read a
- value from the chip.
-
- 2. The system timer is a four-byte value and updated in memory at
- 0040h:006Ch, but only the first three bytes (21 bits) are used because
- it only counts up to 1573040 (1800AFh) ticks per day. At that
- resolution, it only amounts to:
-
- 1573040/(60*60*24) = 18.206481481 ticks/sec
-
- 3. The chip counts down from $0000 negatively until it wraps to zero
- again which then sends the usual interrupt every 1/18.2... seconds to
- update the system timer in the BIOS data area.
-
- 4. Using the chip ports, we can access and lock on to the count down
- timer and get a value. Since it has one full word in the count, the
- total extended resolution of 16 bits is:
-
- 1573040 * 2^16 = 103090749440 ticks/day
- = 1193179.9704 ticks/sec
-
- 5. This total resolution requires a five-byte value to hold the 37 bit
- number. If two days are needed in the calculation which is required
- when passing midnight, a 38 bit value will be needed, but notice that
- it never reaches the full 40 bits of five bytes. This means that
- 6 byte reals are fully capable of handling the value with no loss in
- resolution.
-
-
-
- TIMERH High Precision Timer Page 4
- TIMERH High Precision Timer Documentation, Version 5.5
-
-
- 6. Interrupt control while taking splits was a problem. Since the chip
- and CPU are independent, it is possible that the chip may try to send
- an interrupt on the bus just as the OUT code is being executed. The
- chip will read 0-2 microseconds, but the DOS timer will be one tick
- short. An easy solution is to take two readings of the DOS timer low
- byte and see if they differ - one before the chip is latched and
- another after. If they differ, an extra tick is needed for the system
- timer part of the split only the timer value is small enough (<10000
- microseconds) to confirm that the interrupt did occur.
-
- 7. It is also important that no conditional statements are used in the
- code so that the overhead is constant.
-
- 8. The wake up mode of all timer chips is mode 3, but there is no way to
- use mode 3 on the 8253 with software. The 8254 chip made mode 3
- superior with access to its status register, but software accessing
- this register is incompatible with the IBM PC. So, TIMERH initializes
- with the common mode 2. When the program is terminated, it is
- restored back to mode 3 in case anything else may expect the default
- mode.
-
-
- SUPPORT
-
- If you have questions, comments, or suggestions, the Eagle can be contacted
- by four means - (1) CompuServe, (2) telephone, (3) The Eagle BBS, or
- (4) mail.
-
- CompuServe - The most dependable way to contact the Eagle is through
- CompuServe. James (Jim) H. LeMay has written the Pascal version of TIMERH,
- but the person to contact is Jordan Gallagher who can be contacted on the
- Borland Forum by typing GO BPROGA from the CompuServe main menu. You will
- enter the Forum for Turbo Pascal. You can contact Jordan with his PPN
- number of 73557,2342. Messages can also be left through EasyPlex.
-
- Telephone - Jordan can also be reached by phone at (214) 539-7855 on
- weekdays and Saturday from 9:00 a.m. to 8:00 p.m CST.
-
- The Eagle BBS - You can also contact us on our 24-hour BBS at (214) 539-
- 9878, 1200/2400 N81.
-
- Mail - For problems, please write:
-
- Eagle Performance Software
- P.O. Box 292786
- Lewisville, TX 75029-2786
-
-
- REFERENCE
-
- For more information on the Intel 8253/8254 timer chips, refer to the Intel
- Microsystem Component Handbook, vol 2. You can also call Intel literature
- sales at 1-800-548-4725.
-
-
-
-
- TIMERH High Precision Timer Page 5
- TIMERH High Precision Timer Documentation, Version 5.5
-
-
- REVISIONS
-
- Version 5.5 (01-15-90):
- Original release.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- TIMERH High Precision Timer Page 6
-
- ----------------end-of-author's-documentation---------------
-
- Software Library Information:
-
- This disk copy provided as a service of
-
- Public (software) Library
-
- We are not the authors of this program, nor are we associated
- with the author in any way other than as a distributor of the
- program in accordance with the author's terms of distribution.
-
- Please direct shareware payments and specific questions about
- this program to the author of the program, whose name appears
- elsewhere in this documentation. If you have trouble getting
- in touch with the author, we will do whatever we can to help
- you with your questions. All programs have been tested and do
- run. To report problems, please use the form that is in the
- file PROBLEM.DOC on many of our disks or in other written for-
- mat with screen printouts, if possible. PsL cannot debug pro-
- programs over the telephone, though we can answer questions.
-
- Disks in the PsL are updated monthly, so if you did not get
- this disk directly from the PsL, you should be aware that the
- files in this set may no longer be the current versions. Also,
- if you got this disk from another vendor and are having prob-
- lems, be aware that some files may have become corrupted or
- lost by that vendor. Get a current, working disk from PsL.
-
- For a copy of the latest monthly software library newsletter
- and a list of the 2,000+ disks in the library, call or write
-
- Public (software) Library
- P.O.Box 35705 - F
- Houston, TX 77235-5705
-
- 1-800-2424-PSL
- MC/Visa/AmEx
-
- Outside of U.S. or in Texas
- or for general information,
- Call 1-713-524-6394
-
- PsL also has an outstanding
- catalog for the Macintosh.
-